# Maintainer: Stephan Springer <buzo+arch@Lini.de>
# Contributor: inemum (https://gitlab.com/inemum)
# Contributor: graysky <graysky AT archlinux DOT us>
# Contributor: Fredrick Brennan <copypaste@kittens.ph>

# based on https://git.archlinux.org/svntogit/packages.git/tree/trunk/PKGBUILD?h=packages/sip

pkgbase=python-sip-pyqt4
pkgname=('python-sip-pyqt4' 'python2-sip-pyqt4')
pkgver=4.19.25
pkgrel=3
arch=('x86_64' 'aarch64')
url='http://www.riverbankcomputing.com/software/sip/intro'
license=('custom:"sip"')
makedepends=('python-distutils-extra' 'python2-distutils-extra')
source=("https://www.riverbankcomputing.com/static/Downloads/sip/$pkgver/sip-$pkgver.tar.gz"
        '0001-Fix-compilation-against-Python-3.11.patch')
sha512sums=('60fb4133c68869bf0993144978b4847d94a0f9c7b477f64a346ea133cfe35bc11820204ab327dcf9a929b6f65a26d16cc7efbce65e49967c3347b39376e57001'
            '5cc5fe8e5e5169a183f848623989ca7b5dc7a766fa2fc7b71dd3657e9fdb6986ac1e9de3b2c4ff3b4ed500a522b4b88f8fa2aaac33002ee6b7e607aca9c695de')

prepare() {
  mkdir -p build-pyqt4{,-py2}

  cd "sip-$pkgver"
  patch --strip=1 --input=../0001-Fix-compilation-against-Python-3.11.patch
}

build() {
  cd "$srcdir/build-pyqt4"
  python "../sip-$pkgver/configure.py" CFLAGS="$CFLAGS" LFLAGS="$LDFLAGS" \
    --sip-module PyQt4.sip --no-tools
  make

  cd "$srcdir/build-pyqt4-py2"
  python2 "../sip-$pkgver/configure.py" CFLAGS="$CFLAGS" LFLAGS="$LDFLAGS" \
    --sip-module PyQt4.sip --no-tools
  make
}

package_python-sip-pyqt4() {
  pkgdesc="Python 3.x SIP bindings for C and C++ libraries (PyQt4 version)"
  depends=('python')

  cd build-pyqt4
  make DESTDIR="$pkgdir" install

  install -Dm 644 "../sip-$pkgver/LICENSE" \
    "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

package_python2-sip-pyqt4() {
  pkgdesc="Python 2.x SIP bindings for C and C++ libraries (PyQt4 version)"
  depends=('python2')

  cd build-pyqt4-py2
  make DESTDIR="$pkgdir" install

  install -Dm 644 "../sip-$pkgver/LICENSE" \
    "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

